<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">哈哈</div>
    <ul>
        <li class="item">111</li>
        <li class="item">222</li>
        <li class="item">333</li>
        <li class="item">444</li>
        <li class="item">555</li>
    </ul>
    <script>
        var div1 = document.querySelector('.box');//获取单个对象
        div1.onclick = function () {
            console.log(1);
        }
        div1.onclick = function () {
            console.log(2);
        }
        div1.onclick = function () {
            console.log(3);
        }
        div1.addEventListener('click', function () {
            console.log(4);
        });
        div1.addEventListener('click', function () {
            console.log(5);
        });
        var items = document.querySelectorAll('.item');//获取数组
        for (let i = 0; i < items.length; i++) {
            items[i].addEventListener('click', function () {
                console.log(i);
            });

        }
    </script>
</body>

</html>